home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / STRINGS.SWG / 0090_Basm string routines.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-24  |  3KB  |  62 lines

  1.  
  2. procedure CopySubStr( Str1: string; start, nrchars: byte; var Str2: string );
  3. assembler;
  4.   { copy part of Str1 (beginning at start for nrchars) to Str2
  5.     if start > length of Str1, Str2 will contain a empty string.
  6.     if nrchars specifies more characters than remain starting at the
  7.     start position, Str2 will contain just that remainder of Str1. }
  8. asm
  9.         { setup }
  10.         LDS   SI,Str1      { load in DS:SI pointer to str1 }
  11.         CLD                { string operations forward     }
  12.         LES   DI,Str2      { load in ES:DI pointer to str2 }
  13.         MOV   AH,[SI]      { length str1 --> AH            }
  14.         AND   AH,AH        { length str1 = 0?              }
  15.         JE    @null        { yes, empty string in Str2     }
  16.         MOV   BL,[start]   { starting position --> BL      }
  17.         CMP   AH,BL        { start > length str1?          }
  18.         JB    @null        { yes, empty string in Str2     }
  19.  
  20.         { start + nrchars - 1 > length str1?               }
  21.         MOV   AL,[nrchars] { nrchars --> AL                }
  22.         MOV   DH,AL        { nrchars --> DH                }
  23.         ADD   DH,BL        { add start                     }
  24.         DEC   DH
  25.         CMP   AH,DH        { nrchars > rest of str1?       }
  26.         JB    @rest        { yes, copy rest of str1        }
  27.         JMP   #copy
  28. @null:
  29.         MOV   AL,0         { return a empty string         }
  30.         JMP   #done
  31. @rest:
  32.         SUB   AH,BL        { length str1 - start           }
  33.         INC   AH
  34.         MOV   AL,AH
  35. @copy:
  36.         MOV   CL,AL        { how many chars to copy        }
  37.         XOR   CH,CH        { clear CH                      }
  38.         XOR   BH,BH        { clear BH                      }
  39.         ADD   SI,BX        { starting position             }
  40.         MOV   DX,DI        { save pointer to str2          }
  41.         INC   DI
  42.         REP   MOVSB        { copy part str1 to str2        }
  43.         MOV   DI,DX        { restore pointer to str2       }
  44. @done:
  45.         MOV   [DI],AL      { overwrite length byte of str2 }
  46. @exit:
  47. end  { CopySubStr };
  48.  
  49.  
  50. procedure StrCopy( var Str1, Str2: string ); assembler;
  51.   { copy str1 to str2 }
  52. asm
  53.         LDS   SI,Str1    { load in DS:SI pointer to str1 }
  54.         CLD              { string operations forward     }
  55.         LES   DI,Str2    { load in ES:DI pointer to str2 }
  56.         XOR   CH,CH      { clear CH                      }
  57.         MOV   CL,[SI]    { length str1 --> CX            }
  58.         INC   CX         { include length byte           }
  59.         REP   MOVSB      { copy str1 to str2             }
  60. @exit:
  61. end  { StrCopy };
  62.